package cn.ppool.xmlmapper.init;

import cn.ppool.xmlmapper.ApplicationConfigure;
import cn.ppool.xmlmapper.router.ApiRouter;
import cn.ppool.xmlmapper.router.MainRouter;
import cn.ppool.xmlmapper.sql.RequestSqlService;
import cn.ppool.xmlmapper.sql.SelectObjectPackerService;
import cn.ppool.xmlmapper.sql.SelectObjectPackerServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

@Configuration
public class BeanLoader {

    @Bean
    public RequestSqlService requestSqlService(ApplicationConfigure applicationConfigure) throws InstantiationException, IllegalAccessException {
        return applicationConfigure.getRequestSqlService().newInstance();
    }

    @Bean
    public ApplicationConfigure applicationConfigure() {
        return new ApplicationConfigure();
    }

    @Bean
    public MainRouter mainRouter() {
        return new MainRouter();
    }

    @Bean
    public ApiRouter apiRouter(ApplicationContext context) {
        return new ApiRouter(context);
    }

    @Bean
    @ConditionalOnMissingBean
    public SelectObjectPackerService selectObjectPackerService(ApplicationConfigure applicationConfigure) throws InstantiationException, IllegalAccessException {
        return applicationConfigure.getSelectObjectPackerService().newInstance();
    }



}
